import { Suspense, lazy } from "react"
import { createHashRouter, Navigate } from "react-router"
// import { Spin } from "antd"
import Login from "@/pages/login"

function globalRoute() {
  const Entry = lazy(() => import('@/pages/entry'))
  // const Users = lazy(() => import('@/pages/users'))
  const Home = lazy(() => import('@/pages/home'))
  const LoadingPage = lazy(() => import('@/pages/loadingPage'))
  const NotFound = lazy(() => import('@/pages/notFound'))

  return createHashRouter([
    {
      path: '/login',
      element: <Login />
    },
    {
      path: '/',
      element: (
        <Suspense fallback={ <LoadingPage /> }>
          <Entry />
        </Suspense>
      ),
      children: [
        {
          path: '/home',
          element: <Home />
        },
        // {
        //   path: '/users',
        //   element: <Users />
        // },
        {
          path: '/',
          element: <Navigate to='/home' />
        }
      ]
    },
    {
      path: '*',
      element: <NotFound />
    }
  ])
}

const globalRouter = globalRoute()

export default globalRouter
